package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.AssetPromotion;
import org.apache.ibatis.annotations.*;

import java.util.Date;

public interface AssetPromotionMapper {
    @Delete({
        "delete from asset_promotion",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into asset_promotion (id, type, ",
        "coin_total, coin_used, ",
        "coin_unit, begin_time, ",
        "end_time, create_time)",
        "values (#{id,jdbcType=BIGINT}, #{type,jdbcType=TINYINT}, ",
        "#{coinTotal,jdbcType=INTEGER}, #{coinUsed,jdbcType=INTEGER}, ",
        "#{coinUnit,jdbcType=INTEGER}, #{beginTime,jdbcType=TIMESTAMP}, ",
        "#{endTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(AssetPromotion record);

    int insertSelective(AssetPromotion record);

    @Select({
        "select",
        "id, type, coin_total, coin_used, coin_unit, begin_time, end_time, create_time",
        "from asset_promotion",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    AssetPromotion selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(AssetPromotion record);

    @Update({
        "update asset_promotion",
        "set type = #{type,jdbcType=TINYINT},",
          "coin_total = #{coinTotal,jdbcType=INTEGER},",
          "coin_used = #{coinUsed,jdbcType=INTEGER},",
          "coin_unit = #{coinUnit,jdbcType=INTEGER},",
          "begin_time = #{beginTime,jdbcType=TIMESTAMP},",
          "end_time = #{endTime,jdbcType=TIMESTAMP},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(AssetPromotion record);

    // ********

//    @Select({
//            "select",
//            "id, type, coin_total, coin_used, coin_unit, begin_time, end_time, create_time",
//            "from asset_promotion",
//            "where begin_time < #{registerTime,jdbcType=TIMESTAMP} and end_time > #{registerTime,jdbcType=TIMESTAMP} order by id asc limit 1"
//    })
    @ResultMap("BaseResultMap")
    AssetPromotion selectByTime(@Param("registerTime") Date registerTime);
}